from rest_framework.views import exception_handler
from django.contrib.gis.geos.error import GEOSException

def custom_exception_handler(exc, context):
    """自定义异常处理"""
    response = exception_handler(exc, context)
    
    if isinstance(exc, GEOSException):
        response.data = {
            'code': 'invalid_geo',
            'detail': '地理位置数据无效',
            'field': 'location'
        }
    
    return response